package com.pureut.scheduling.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.scheduling.domain.SchedulingHours;
import com.pureut.scheduling.domain.dto.SchedulingHoursDto;
import com.pureut.scheduling.domain.vo.SchedulingHoursVo;
import com.pureut.scheduling.service.ISchedulingHoursService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description 标准工时控制层
 * @Param SchedulingHours
 * @Date 22-12-23
 * @Author hl
 **/
@RestController
@RequestMapping("/standardHours")
public class SchedulingHoursController extends BaseController {

    @Resource
    private ISchedulingHoursService schedulingHoursService;

    /**
     * 查询标准工时
     */
    @RequiresPermissions("schedule:scheduleConfig:standardHours:list")
    @GetMapping("/list")
    public TableDataInfo list(SchedulingHoursVo schedulingHoursVo) {
        startPage();
        List<SchedulingHoursDto> list = schedulingHoursService.selectHoursList(schedulingHoursVo);
        return getDataTable(list);
    }

    /**
     * 新增标准工时
     */
    @RequiresPermissions("schedule:scheduleConfig:standardHours:add")
    @Log(title = "标准工时", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SchedulingHours schedulingHours) throws Exception {
        return toAjax(schedulingHoursService.insertSchedulingHours(schedulingHours));
    }

    /**
     * 根据编号获取详细信息
     */
    @RequiresPermissions("schedule:scheduleConfig:standardHours:query")
    @GetMapping(value = "/{hoursId}")
    public AjaxResult getModelingInfo(@PathVariable long hoursId) {
        return AjaxResult.success(schedulingHoursService.selectHoursById(hoursId));
    }


    /**
     * 修改标准工时
     */
    @RequiresPermissions("schedule:scheduleConfig:standardHours:edit")
    @Log(title = "标准工时", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody SchedulingHours schedulingHours) throws Exception {
        return toAjax(schedulingHoursService.updateSchedulingHoursEdit(schedulingHours));
    }

    /**
     * 批量删除标准工时
     */
    @RequiresPermissions("schedule:scheduleConfig:standardHours:remove")
    @DeleteMapping("/{hoursId}")
    public AjaxResult remove(@PathVariable("hoursId") String hoursId) throws Exception {
        return toAjax(schedulingHoursService.deleteHoursById(hoursId));
    }

    /**
     * 根据线别查询相关信息
     */
    @GetMapping("/hoursLine")
    public AjaxResult hoursLine(long hoursLineId) {
        return AjaxResult.success(schedulingHoursService.selectHoursLineById(hoursLineId));
    }

    /**
     * 根据线别id 和物料编码 查询对应工时
     */
    @GetMapping("/hoursOnById")
    public AjaxResult hoursOnById(long lineId, String materialCode) {
        return AjaxResult.success(schedulingHoursService.selectHoursOnById(lineId,materialCode));
    }

}
